package com.my.ph.util;

import lombok.Getter;

/**
 * @author mayan50
 * 同意返回类
 * @param <T>
 */
@Getter
public class R<T> {

    private final int code;
    private final String msg;
    private final T data;

    private R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> R<T> ok() {
        return new R<>(200, "请求成功！", null);
    }

    public static <T> R<T> ok(String msg) {
        return new R<>(200, msg, null);
    }

    public static R<String> okStr(String data) {
        return new R<>(200, "请求成功！", data);
    }

    public static <T> R<T> ok(T data) {
        return new R<>(200, "请求成功！", data);
    }

    public static <T> R<T> ok(String msg, T data) {
        return new R<>(200, msg, data);
    }

    public static <T> R<T> error(int code, String msg) {
        return new R<>(code, msg, null);
    }

    public static <T> R<T> error(int code, String msg, T data) {
        return new R<>(code, msg, data);
    }

    public static <T> R<T> error(String msg) {
        return new R<>(500, msg, null);
    }

}
